Visual Basic (Declaration) | |
---|---|
Public Function New( _ ByVal comparer As IComparer(Of T) _ ) |
C# | |
---|---|
public SetList<T>( IComparer<T> comparer ) |
Parameters
- comparer
Library/Library.Test/TestSetList.cs
C# | Copy Code |
---|---|
IList list = new SetList<string>(StringComparer.Ordinal); Assert.AreEqual(0, list.Count); list.Add("a"); Assert.AreEqual(1, list.Count); list.Add("B"); Assert.AreEqual(2, list.Count); Assert.AreEqual("B", list[0]); Assert.AreEqual("a", list[1]); Assert.IsTrue(list.Contains("a")); Assert.IsFalse(list.Contains("A")); Assert.IsFalse(list.Contains("b")); Assert.IsTrue(list.Contains("B")); Assert.AreEqual(0, list.IndexOf("B")); Assert.AreEqual(1, list.IndexOf("a")); list = new SetList<string>((IEnumerable<string>)list, StringComparer.OrdinalIgnoreCase); Assert.AreEqual(2, list.Count); Assert.AreEqual("a", list[0]); Assert.AreEqual("B", list[1]); Assert.IsTrue(list.Contains("a")); Assert.IsTrue(list.Contains("A")); Assert.IsTrue(list.Contains("b")); Assert.IsTrue(list.Contains("B")); Assert.IsFalse(list.Contains(5)); Assert.IsTrue(list.IndexOf(5) < 0); Assert.IsFalse(list.IsFixedSize); list.Remove("b"); Assert.IsFalse(list.Contains("b")); Assert.IsFalse(list.Contains("B")); list = (IList)((ICloneable)list).Clone(); Assert.AreEqual(typeof(SetList<string>), list.GetType()); Assert.IsTrue(list.Contains("a")); Assert.IsFalse(list.Contains("b")); Assert.AreEqual(0, list.IndexOf("a")); |
VB.NET | Copy Code |
---|---|
Dim list As IList = New SetList(Of String)(StringComparer.Ordinal) Assert.AreEqual(0, list.Count) list.Add("a") Assert.AreEqual(1, list.Count) list.Add("B") Assert.AreEqual(2, list.Count) Assert.AreEqual("B", list(0)) Assert.AreEqual("a", list(1)) Assert.IsTrue(list.Contains("a")) Assert.IsFalse(list.Contains("A")) Assert.IsFalse(list.Contains("b")) Assert.IsTrue(list.Contains("B")) Assert.AreEqual(0, list.IndexOf("B")) Assert.AreEqual(1, list.IndexOf("a")) list = New SetList(Of String)(DirectCast(list, IEnumerable(Of String)), StringComparer.OrdinalIgnoreCase) Assert.AreEqual(2, list.Count) Assert.AreEqual("a", list(0)) Assert.AreEqual("B", list(1)) Assert.IsTrue(list.Contains("a")) Assert.IsTrue(list.Contains("A")) Assert.IsTrue(list.Contains("b")) Assert.IsTrue(list.Contains("B")) Assert.IsFalse(list.Contains(5)) Assert.IsTrue(list.IndexOf(5) < 0) Assert.IsFalse(list.IsFixedSize) list.Remove("b") Assert.IsFalse(list.Contains("b")) Assert.IsFalse(list.Contains("B")) list = DirectCast((DirectCast(list, ICloneable)).Clone(), IList) Assert.AreEqual(GetType(SetList(Of String)), list.[GetType]()) Assert.IsTrue(list.Contains("a")) Assert.IsFalse(list.Contains("b")) Assert.AreEqual(0, list.IndexOf("a")) |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
Reference
SetList<T> ClassSetList<T> Members
Overload List